//
//  EmulateViewController.m
//  用到富文本
//
//  Created by dcr on 2017/8/28.
//  Copyright © 2017年 邓兆太. All rights reserved.
//

#import "EmulateViewController.h"
#import "ExaminationViewController.h"

@interface EmulateViewController ()

@end

@implementation EmulateViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self initWidgets];
}

- (void)initWidgets{
    WS(ws);
    CGFloat top = 100;
    CGFloat height = 40;
    UILabel *label1 = [UILabel new];
    label1.font = WeekFont3;
    label1.textAlignment = NSTextAlignmentLeft;
    label1.numberOfLines = 0;
    label1.text = @"考试科目：科目一理论考试";
    
    [self.view addSubview:label1];
    [label1 mas_makeConstraints:^(MASConstraintMaker *make){
        make.left.mas_equalTo(30);
        make.topMargin.mas_equalTo(top);
        make.size.mas_equalTo(CGSizeMake(ws.view.width, height));
    }];

    UILabel *label2 = [UILabel new];
    label2.font = WeekFont3;
    label2.textAlignment = NSTextAlignmentLeft;
    label2.numberOfLines = 0;
    NSMutableAttributedString *attrStr2 = [[NSMutableAttributedString alloc] initWithString:@"考试车型：小车（C1,C2,C3,C4）"];
    [attrStr2 addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(5, 15)];
    label2.attributedText = attrStr2;
    
    [self.view addSubview:label2];
    [label2 mas_makeConstraints:^(MASConstraintMaker *make){
        make.left.mas_equalTo(30);
        make.topMargin.mas_equalTo(top + height);
        make.size.mas_equalTo(CGSizeMake(ws.view.width, height));
    }];

    UILabel *label3 = [UILabel new];
    label3.font = WeekFont3;
    label3.textAlignment = NSTextAlignmentLeft;
    label3.numberOfLines = 0;
    NSMutableAttributedString *attrStr3 = [[NSMutableAttributedString alloc] initWithString:@"考试标准：100题，45分钟"];
    [attrStr3 addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(5, 9)];
    label3.attributedText = attrStr3;
    
    [self.view addSubview:label3];
    [label3 mas_makeConstraints:^(MASConstraintMaker *make){
        make.left.mas_equalTo(30);
        make.topMargin.mas_equalTo(top + height*2);
        make.size.mas_equalTo(CGSizeMake(ws.view.width, height));
    }];

    UILabel *label4 = [UILabel new];
    label4.font = WeekFont3;
    label4.textAlignment = NSTextAlignmentLeft;
    label4.numberOfLines = 0;
    NSMutableAttributedString *attrStr4 = [[NSMutableAttributedString alloc] initWithString:@"全格标准：满分100分，90分合格"];
    [attrStr4 addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(5, 12)];
    label4.attributedText = attrStr4;
    
    [self.view addSubview:label4];
    [label4 mas_makeConstraints:^(MASConstraintMaker *make){
        make.left.mas_equalTo(30);
        make.topMargin.mas_equalTo(top + height*3);
        make.size.mas_equalTo(CGSizeMake(ws.view.width, height));
    }];
    
    NSArray *btns = [NSArray arrayWithObjects:@"全真模拟考试", @"优先考未做题", nil];
    for(int i = 0; i < btns.count; i++){
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
        btn.backgroundColor = [UIColor colorWithRed:0.38 green:0.42 blue:1.00 alpha:1.00];
        btn.layer.masksToBounds = YES;
        btn.layer.cornerRadius = 15;
        btn.tag = 2000+i;
        [btn addTarget:self action:@selector(onClickButton:) forControlEvents:UIControlEventTouchUpInside];
        [btn setTitle:btns[i] forState:UIControlStateNormal];
        [btn setTitleColor:KWhiteColor forState:UIControlStateNormal];
        [btn.titleLabel setFont:WeekFont3];
        [self.view addSubview:btn];
        CGFloat x = (MainScreenWidth/4.0) + (MainScreenWidth/2.0)*i - 60;
        [btn mas_makeConstraints:^(MASConstraintMaker *make){
            make.left.mas_equalTo(x);
            make.topMargin.mas_equalTo(top + height*5);
            make.size.mas_equalTo(CGSizeMake(120, 40));
        }];
    }
}

- (void)onClickButton:(UIButton *)btn{
    DLog(@"onClickButton tag = %d", btn.tag);
    if(btn.tag == 2000){
        ExaminationViewController *controller = [[ExaminationViewController alloc]init];
        controller.model = emulatePractice;
        [self.navigationController showViewController:controller sender:nil];
    }else if(btn.tag == 2001){
        ExaminationViewController *controller = [[ExaminationViewController alloc]init];
        controller.model = preferredNotAnswer;
        [self.navigationController showViewController:controller sender:nil];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
